C to C++ Conversion [closed]

Posted by Annalyne on Game Development See other posts from Game Development or by Annalyne
Published on 2012-09-08T15:29:43Z Indexed on 2012/09/08 15:50 UTC
Read the original article Hit count: 264

Filed under:
|

Can someone convert this code to C++, pretty please? :(

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define WEAPON_ROPE        10
#define WEAPON_REVOLVER    20
#define WEAPON_LEADPIPE    30
#define WEAPON_CANDLESTICK 40
#define WEAPON_KNIFE       50
#define WEAPON_WRENCH      60

#define PEOPLE_MRGREEN     100
#define PEOPLE_MSSCARLET   200
#define PEOPLE_CONLMUSTARD 300
#define PEOPLE_PROFPLUM    400
#define PEOPLE_MISPEACOCK  500
#define PEOPLE_MISWHITE    600

#define PLACE_KITCHEN      1
#define PLACE_HALL         2
#define PLACE_POOLROOM     3
#define PLACE_STUDY        4
#define PLACE_LOUNG        5
#define PLACE_LIBRARY      6
#define PLACE_CONSERVATORY 7
#define PLACE_DINING       8
#define PLACE_BILLIARDS    9

int main()
{
    int die = 0;
    int players[6][9] = {{0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0}};

    int allCards[] = {WEAPON_ROPE, WEAPON_REVOLVER,
                      WEAPON_LEADPIPE, WEAPON_CANDLESTICK,
                      WEAPON_CANDLESTICK, WEAPON_KNIFE,
                      WEAPON_WRENCH,
                      PEOPLE_MRGREEN, PEOPLE_MSSCARLET,
                      PEOPLE_CONLMUSTARD, PEOPLE_CONLMUSTARD,
                      PEOPLE_PROFPLUM, PEOPLE_MISPEACOCK,
                      PEOPLE_MISWHITE,
                      PLACE_KITCHEN, PLACE_HALL,
                      PLACE_POOLROOM, PLACE_STUDY,
                      PLACE_LOUNG, PLACE_LIBRARY,
                      PLACE_CONSERVATORY, PLACE_DINING,
                      PLACE_BILLIARDS};
    int deckSize = 23; // number of cards in allCards array

    int count;
    for (count = 0; count < deckSize; ++count)
    {
        printf(", %d", allCards[count]);
    } // End for

  // These three array's are so you can put a card back, if need be...
    int weaponCards[] = {WEAPON_ROPE, WEAPON_REVOLVER,
                         WEAPON_LEADPIPE, WEAPON_CANDLESTICK,
                         WEAPON_CANDLESTICK, WEAPON_KNIFE,
                         WEAPON_WRENCH};
    int weaponDeckSize = 7;


    int peopleCards[] = {PEOPLE_MRGREEN, PEOPLE_MSSCARLET,
                         PEOPLE_CONLMUSTARD, PEOPLE_CONLMUSTARD,
                         PEOPLE_PROFPLUM, PEOPLE_MISPEACOCK,
                         PEOPLE_MISWHITE};
    int peopleDeckSize = 7;


    int placeCards[] = {PLACE_KITCHEN, PLACE_HALL,
                        PLACE_POOLROOM, PLACE_STUDY,
                        PLACE_LOUNG, PLACE_LIBRARY,
                        PLACE_CONSERVATORY, PLACE_DINING,
                        PLACE_BILLIARDS};
    int placeDeckSize = 9;

    srand(clock()); // seed rand() using clock() which gives
                    //   the current tick your processor is at...

    int killer[3]; // no need to initialize yet.  killer[0-2] will initialize

    int deckShuffle = rand() % weaponDeckSize; // picks one number out of the deck
    killer[0] = weaponCards[deckShuffle];
    allCards[deckShuffle] = 0; // Card drawn.  No longer exists in deck

    deckShuffle = rand() % peopleDeckSize; // picks another random card out of the deck
    killer[1] = peopleCards[deckShuffle];
    allCards[deckShuffle + weaponDeckSize] = 0; // Card drawn.  No longer exists in deck

    deckShuffle = rand() % placeDeckSize; // randomly picks the last card needed
    killer[2] = placeCards[deckShuffle];
    allCards[deckShuffle + weaponDeckSize + peopleDeckSize] = 0; // Card drawn.  No longer exists in deck


    int numberOfCards = 0;
    printf("CLUE\n");
    printf("written by John Schintone\n");
    printf("Origonal game delvoped by Hasbro\n");

    int numberOfPlayers = 0;
    while ((numberOfPlayers < 3) || (numberOfPlayers > 6))
    {
        printf("How many players are Going to play :\n");
        printf("[number] > ");
        scanf("%d",&numberOfPlayers);

        // A very fast if statement which only uses integers/char's
        switch(numberOfPlayers)
        {
            case 6:
            {
                numberOfCards = 3;
            } break;

            case 5:
            {
                numberOfCards = 4;
            } break;

            case 4:
            {
                numberOfCards = 5;
            } break;

            case 3:
            {
                numberOfCards = 6;
            } break;

            default:
            {
                printf("You must enter a number between 3 and 6...\n");
            } // End default
        } // End switch
    } // End while

    int index1, index2;
    // Note: ++index1; is faster than index1++; and will almost always
    //         produce better code (index1++ happens after this statement line.
    //         ++index1 increments index1 before this statement line)
    for (index1 = 0; index1 < numberOfPlayers; ++index1)
    {
        printf("Player %d", index1);
        for (index2 = 0; index2 < numberOfCards; ++index2)
        {
            // Remember that allCards[deckShuffle] == 0 because we removed that
            //   card ages ago...  works out well, just don't forget you did that : )
            while (allCards[deckShuffle] == 0)
            {
                deckShuffle = rand() % deckSize;
            } // End while

            players[index1][index2] = allCards[deckShuffle];
            allCards[deckShuffle] = 0; // Card removed for after loop...

            printf(", %d", players[index1][index2]);

            switch(players[index1][index2])
            {
                case WEAPON_ROPE:
                {
                } break;

                // Add more...

                case PEOPLE_MRGREEN:
                {
                } break;

                // Add more...

                case PLACE_KITCHEN:
                {
                } break;

                // Add more...

                default:
                {
                    printf("Program has caught player %d cheating...", index1);
                } // End default
            } // End switch
        } // End for

        printf("\n");
    } // End for

    printf("The killer is %d, with the %d, and in the %d \n\n", killer[0], killer[1], killer[2]);

    printf("Type h for this help... \n");
    printf("Type e to escape... \n");
    printf("Type r to roll the die... \n");

    char command = '\0';  // \0 represents zero, or the null character
    while (command != 'e')
    {
        printf("[one character] > ");
        scanf("%c", &command);

        if (command == 'r')
        {

          die = rand() % 6 + 1;

          printf("Your number is: %d \n", die);
        } // end while

        if (command == 'h')
        {
            printf("Type h for this help... \n");
            printf("Type e to escape... \n");
            printf("Type r to roll the die... \n");
        } // End if

        printf("\n");
    } // End while

    return(0); // Success.  Program worked ok
} // End main() Function

© Game Development or respective owner

Related posts about c++

Related posts about c